package cn.com.callback

import java.util.Map;
import cn.com.elite.EliteBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.elite.Util;
import cn.com.elite.PropertiesUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
/**
 * 
 * @author msjykf
 * 重新计算客户分组数据
 * {"groupid":"","tbname":""}
 *
 */
public class CustomerGroupCalculate implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(CustomerGroupCalculate.class);
	public String doCallBack(EliteBean eliteBean, HttpServletRequest request,HttpServletResponse response){
		try {
			def jsonbody = Util.getRequestBody(request,'utf-8'); //获取报文
			if(jsonbody.equals("")) {
				return "{\"msg\": \"未获取到入参报文！\",\"code\": -2}"
			}
			JSONObject obj = JSONObject.fromObject(jsonbody);
			def groupid = Util.filterForObject(obj.get("groupid"));
			def tbname = Util.filterForObject(obj.get("tbname"));
			if(groupid.equals("")||tbname.equals("")) {
				return "{\"msg\": \"分组信息不能为空！\",\"code\": -2}"
			}
			def smap = eliteBean.chaxun_sql("select count(*) as custtotalnum,sum(f_get_validated_flag('MOBILENO',mobile_phone)) as validmobilenum,sum(f_get_validated_flag('EMAIL',email)) as validemailnum from "+tbname+"","dataSource");
			def custtotalnum = smap[0].get("custtotalnum");
			
		}catch (Exception e) {
			log.error("ErrorMessage",e);
			return "{\"code\":\"-1\",\"msg\":\"接口调用失败！\"}";
		}	
	}
}